package gmusic;

import java.util.*;

public class Normalisation {
	public static String normaliser(String chaine) {
		
		StringBuffer nvChaine = new StringBuffer("");
		String token;
		
		// On remplace "_" par " "
		chaine = chaine.replaceAll("_"," ");
		chaine = chaine.replaceAll("  "," ");
		
		// Majuscule apres chaque espace
		StringTokenizer st = new StringTokenizer(chaine, " ");
		while (st.hasMoreTokens()) {
			token = st.nextToken();
	     		nvChaine.append(token.substring(0,1).toUpperCase()+token.substring(1,token.length())+" ");
	     	}
	     	
	     	chaine = nvChaine.toString();
	     	nvChaine = new StringBuffer("");
	     	
		// Majuscule apres chaque '('
		st = new StringTokenizer(chaine, "(");
		while (st.hasMoreTokens()) {
			token = st.nextToken();
	     		nvChaine.append(token.substring(0,1).toUpperCase()+token.substring(1,token.length())+"(");
	     	}
	     	
	     	chaine = nvChaine.toString();
	     	if (chaine.substring(chaine.length()-1,chaine.length()).equals("("))
	     		chaine = chaine.substring(0,chaine.length()-1);
	     	
		return chaine.trim();
	}
}